// https://www.acwing.com/problem/content/900/

#include <iostream>
#include <vector>
#include <climits>
using namespace std;

const int N = 508;
int nums[N][N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=i; j++) {
            scanf("%d", &nums[i][j]);
        }
    }
    vector<vector<int>> dp(N, vector<int>(N, INT_MIN));
    dp[1][1] = nums[1][1];

    for (int i=2; i<=n; i++) {
        for (int j=1; j<=i; j++) {
            dp[i][j] = nums[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j]);
        }
    }

    int maxElement = dp[n][1];
    for (int i=1; i<=n; i++) {
        maxElement = max(maxElement, dp[n][i]);
    }
    cout<<maxElement<<endl;
    return 0;
}


/*
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

[30]


10
-6
-4 -5
-3 7 5
3 7 -2 1
10 2 -6 2 -6
-8 3 8 6 7 9
-4 -10 0 -3 4 9 2
0 5 5 5 10 -6 -5 -4
-9 7 4 9 8 -5 -2 3 2
-7 -4 0 -10 -8 -4 3 -5 8 9

[25]
 */